<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('采购订单列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>订单号：</label>
                            <input type="text" name="orderNo"/>
                        </li>
                        <li>
                            <label >供应商名称：</label>
                            <input type="text" name="supplierName"/>
                        </li>
                        <li>
                            <label>仓库名称：</label>
                            <input type="text" name="warehouseName"/>
                        </li>
                        <li>
                            <label >业务责任人：</label>
                            <input type="text" name="businessManager"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var orderStatusDatas = [[${@dict.getType('order_status')}]];
    var deliveryStatusDatas = [[${@dict.getType('delivery_status')}]];
    var payStatusDatas = [[${@dict.getType('pay_status')}]];
    var unitDatas = [[${@dict.getType('product_unit')}]];
    var prefix = ctx + "order/purchorder";

    $(function () {
        var options = {
            url: prefix + "/selectList",
            modalName: "采购订单",
            detailView: true,
            onExpandRow : function(index, row, $detail) {
                initChildTable(index, row, $detail);
            },
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'orderNo',
                    title: '订单号'
                },
                {
                    field: 'supplierName',
                    title: '供应商名称'
                },
                {
                    field: 'warehouseName',
                    title: '仓库名称'
                },
                {
                    field: 'sendUser',
                    title: '送货人'
                },
                {
                    field: 'businessManager',
                    title: '业务责任人'
                },
                {
                    field: 'orderDate',
                    title: '发货时间'
                },
                {
                    field: 'orderStatus',
                    title: '订单状态',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(orderStatusDatas, value);
                    }
                },
                {
                    field: 'deliveryStatus',
                    title: '运输状态',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(deliveryStatusDatas, value);
                    }
                },
                {
                    field: 'payStatus',
                    title: '付款状态',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(payStatusDatas, value);
                    }
                },
                {
                    field: 'nums',
                    title: '采购数量'
                },
                {
                    field: 'amounts',
                    title: '采购金额'
                },
                {
                    field: 'payAmounts',
                    title: '付款金额'
                }]
        };
        $.table.init(options);
    });

    initChildTable = function(index, row, $detail) {
        var childTable = $detail.html('<table style="table-layout:fixed"></table>').find('table');
        $(childTable).bootstrapTable({
            url: prefix + "/item/list",
            method: 'post',
            sidePagination: "server",
            contentType: "application/x-www-form-urlencoded",
            queryParams: {
                mainId: row.id
            },
            columns: [
                {
                    field: 'id',
                    title: 'id',
                    visible: false
                },
                {
                    field: 'batchNo',
                    title: '批次'
                },
                {
                    field: 'goodsCode',
                    title: '商品编码'
                },
                {
                    field: 'goodsName',
                    title: '商品名称'
                },
                {
                    field: 'goodsUnit',
                    title: '单位',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(unitDatas, value);
                    }
                },
                {
                    field: 'planNumber',
                    title: '数量'
                },
                {
                    field: 'price',
                    title: '单价'
                },
                {
                    field: 'amount',
                    title: '总价'
                },
                {
                    field: 'remark',
                    title: '要求'
                }
            ]

        });

    };
</script>
</body>
</html>